﻿using CPPEI.Coolzon.UI.XProperty;
using CPPEI.Coolzon.UI.XProperty.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace CPPEI.Coolzon.UI.DataPartLib.XProperty.Converters
{
    /// <summary>
    /// 条件控件转换
    /// </summary>
    public class XCondionImageConvert : IPropertyValueConverter
    {
        public object Convert(ConvertContext context, Metadata.ValueNode valueNode)
        {
            List<ConditionImage> conditionImageList = new List<ConditionImage>();
            if (valueNode.Name.Equals("Condition.Prefix") || valueNode.Name.Equals("Condition.Suffix"))
            {

                foreach (Metadata.ValueNode conditionImageNode in valueNode.ValueNodes)
                {
                    ConditionImage conditionImage = new ConditionImage();
                    foreach (Metadata.ValueNode conditionNode in conditionImageNode.ValueNodes)
                    {
                        if (conditionNode.Name.Equals("ConditionImage.ImageSource"))
                        {
                            Metadata.ValueNode imageNode = conditionNode.ValueNodes.Where(p => p.Name.Equals("ImageSource")).First();
                            XImageSourceFileConverter xImageSourceConverter = new XImageSourceFileConverter();
                            conditionImage.ImageSource = (ImageSourceFile)xImageSourceConverter.Convert(context, imageNode);
                        }
                        else if (conditionNode.Name.Equals("ConditionImage.Condtion"))
                        {
                            conditionImage.Condition = conditionNode.Value;
                        }
                    }
                    conditionImageList.Add(conditionImage);
                }
            }
            return conditionImageList;
        }

        public Metadata.ValueNode ConvertBack(ConvertContext context, object value)
        {
            return null;
        }
    }
}
